package com.hugong.yxx.wksp.persistence.entity;

import com.baomidou.mybatisplus.enums.IdType;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.activerecord.Model;
import com.hugong.yxx.wksp.common.bean.UserBean;
import com.hugong.yxx.wksp.common.utils.Setting;
import lombok.Data;

import java.io.Serializable;

/**
 * <p>
 *
 * </p>
 *
 * @author ${author}
 * @since 2019-08-13
 */
@Data
public class User extends Model<User> {

    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    @TableId(value = "userID", type = IdType.AUTO)
    private Integer userID;
    /**
     * 账号
     */
    private String username;
    /**
     * 用户头像地址
     */
    private String photoUrl;
    /**
     * 用户号码
     */
    private String cellphone;
    /**
     * 用户昵称
     */
    private String usercode;
    /**
     * 用户密码
     */
    private String password;
    /**
     * 微信号
     */
    private String weixinID;
    /**
     * 用户地址
     */
    private String userUrl;
    /**
     * 性别
     */
    private Integer sex;
    /**
     * 登录方式 1：微信登录 2：手机号登录
     *
     * @return
     */
    private Integer registerType;

    public User() {
    }

    public static User getUserByUserBean(UserBean userBean) {
        User user = new User();
        user.username = userBean.getOpenid();
        user.photoUrl = userBean.getHeadimgurl();
        user.usercode = userBean.getNickname();
        user.weixinID = userBean.getOpenid();
        user.userUrl = userBean.getCity();
        user.registerType = Setting.WEIXIN_REGISTER;
        return user;
    }


    @Override
    protected Serializable pkVal() {
        return this.userID;
    }

    @Override
    public String toString() {
        return "User{" +
                ", userID=" + userID +
                ", photoUrl=" + photoUrl +
                ", cellphone=" + cellphone +
                ", username=" + username +
                ", password=" + password +
                ", weixinID=" + weixinID +
                ", userUrl=" + userUrl +
                ", sex=" + sex +
                "}";
    }
}
